#!/bin/bash

release_version=1.2.1

dist_dir=dist

if [ -d "$dist_dir" ]
then
	rm -rf "$dist_dir"
fi
mkdir "$dist_dir"

chmod +x additional_scripts/a1.sh

###########################################################
# make patch
###########################################################
sed -i "s/%%release_version%%/$release_version/" ./additional_scripts/install.sh

patch_name=update${release_version}_`date +"%Y_%m_%d_%H_%M"`
tar zcvf $dist_dir/${patch_name}.tgz --exclude='dist' --exclude='.svn' --exclude='make*.sh' *

# reset the version number
svn revert additional_scripts/install.sh

############################################################
# make bin file
############################################################
cp bin.template dist/
pushd dist > /dev/null
cat ${patch_name}.tgz >> bin.template
mv bin.template ${patch_name}.bin
chmod u+x ${patch_name}.bin

############################################################
# make md5sum file
############################################################
md5sum ${patch_name}.bin > $patch_name.bin.md5sum
popd > /dev/null